package Utils;

import org.junit.Test;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Dateoperation {
    private Date date;
    private SimpleDateFormat dateFormat;
    private String year;
    private String month;
    private String day;
    private String hours;
    private String minutes;
    private String second;
    public static final char SEPRTOR='/';
    public String getYear() {
        date = new Date();
        dateFormat = new SimpleDateFormat("yyyy");
        year = dateFormat.format(date.getTime());
        return year;
    }

    public Date getDate() {
        return date;
    }

    public void setDate(Date date) {
        this.date = date;
    }

    public SimpleDateFormat getDateFormat() {
        return dateFormat;
    }

    public void setDateFormat(SimpleDateFormat dateFormat) {
        this.dateFormat = dateFormat;
    }

    public void setYear(String year) {
        this.year = year;
    }

    public String getMonth() {
        date = new Date();
        dateFormat = new SimpleDateFormat("MM");
        month = dateFormat.format(date.getTime());
        return month;
    }

    public void setMonth(String month) {

        this.month = month;
    }

    public String getDay() {
        date = new Date();
        dateFormat = new SimpleDateFormat("dd");
        day = dateFormat.format(date.getTime());
        return day;
    }

    public void setDay(String day) {
        this.day = day;
    }

    public String getHours() {
        date = new Date();
        dateFormat = new SimpleDateFormat("hh");
        hours = dateFormat.format(date.getTime());
        return hours;
    }

    public void setHours(String hours) {
        this.hours = hours;
    }

    public String getMinutes() {
        date = new Date();
        dateFormat = new SimpleDateFormat("mm");
        minutes = dateFormat.format(date.getTime());
        return minutes;
    }

    public void setMinutes(String minutes) {
        this.minutes = minutes;
    }

    public String getSecond() {
        date = new Date();
        dateFormat = new SimpleDateFormat("ss");
        second = dateFormat.format(date.getTime());
        return second;
    }

    public void setSecond(String second) {
        this.second = second;
    }

    /**
     * 返回时间格式为YYYY/MM/DD hh:mm:ss
     */
    @Test
    public Date getcurrentTime() throws ParseException {
        date = new Date();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yy/MM/dd");
        String formatDate = dateFormat.format(date);
        System.out.println("formatDate" + formatDate);

        SimpleDateFormat dateFormat1= new SimpleDateFormat("yyyy/MM/dd hh:mm:ss");
        String tempTime=dateFormat1.format(date);
        System.out.println("tempTime yyyy/MM/dd hh:mm:ss:"+tempTime);
        return dateFormat1.parse(tempTime);
    }
    @Override
    public String toString() {
        return "Dateoperation{" +
                "date=" + date +
                ", dateFormat=" + dateFormat +
                ", year='" + year + '\'' +
                ", month='" + month + '\'' +
                ", day='" + day + '\'' +
                ", hours='" + hours + '\'' +
                ", minutes='" + minutes + '\'' +
                ", second='" + second + '\'' +
                '}';
    }
}
